<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <!--准备好一个“容器”-->
    <div id="test"></div>
    <div id="test1"></div>

    <!--引入react核心库,必须在dom前面引入-->
    <script type="text/javascript" src="../js/react.development.js"></script>
    <!--引入react_dom，用于支持react操作DOM-->
    <script type="text/javascript" src="../js/react-dom.development.js"></script>
    <!--引入babel，用于将jsx转为js-->
    <script type="text/javascript" src="../js/babel.min.js"></script>
    <!--引入prop-types，用于对组件标签属性进行限制-->
    <script type="text/javascript" src="../js/prop-types.js"></script>
    <script type="text/babel">
        // 创建组件
        class Person extends React.Component{
            render(){
               // const {name,sex,age} = this.props
                // props是只读的
                return(
                    <div>
                        <ul>
                            <li>姓名：{this.props.name}</li>
                            <li>性别：{this.props.sex}</li>
                            <li>年龄：{this.props.age+1}</li>
                        </ul>
                    </div>
                )
            }
        }
        // 对标签属性进行类型限制、必要性的限制
        Person.propTypes = {
            name:PropTypes.string.isRequired, // 限制name为字符串且必传
            sex:PropTypes.string,
            age:PropTypes.number,
            speak:PropTypes.func // 限制speak是个函数
        }
        // 指定默认标签属性值
        Person.defaultProps = {
            sex:'不男不女',
            age:18
        }
        ReactDOM.render(<Person name="蕾蕾" sex="女" age={18} speak={speak}/>,document.getElementById('test'))

        const p = {name:'楠楠',sex:'女',age:21}
        ReactDOM.render(<Person {...p}/>,document.getElementById('test1'))

        function speak(){
            console.log('我是speak')
        }
    </script>

</body>
</html>